﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace sp500
{
    class DataAdapter2Table
    {
        private Sp500QuteHistoryList m_quteHistoryList;
        private DataTable m_datatable;

        public DataAdapter2Table(Sp500QuteHistoryList quteHistoryList)
        {
            m_quteHistoryList = quteHistoryList;
        }

        public DataTable adapter2Datasource()
        {
            DataTable datatable = new DataTable();

            // TODO!!!
            // Here I just hard code the data table value and type
            // should be separated
            // for convenient
            //datatable.Columns.Add("Date", typeof(string));
            //datatable.Columns.Add("Open", typeof(double));
            //datatable.Columns.Add("High", typeof(double));
            //datatable.Columns.Add("Low", typeof(double));
            //datatable.Columns.Add("Close", typeof(double));
            //datatable.Columns.Add("Volume", typeof(int));
            //datatable.Columns.Add("Adj Close", typeof(double));

            datatable.Columns.Add("Date", typeof(string));
            datatable.Columns.Add("Open", typeof(string));
            datatable.Columns.Add("High", typeof(string));
            datatable.Columns.Add("Low", typeof(string));
            datatable.Columns.Add("Close", typeof(string));
            datatable.Columns.Add("Volume", typeof(string));
            datatable.Columns.Add("Adj Close", typeof(string));


            List<Sp500Dailyquote>  historylist = m_quteHistoryList.getHistoryqute();
            foreach (Sp500Dailyquote quotedaily in historylist)
            {
                datatable.Rows.Add(
                    new string[] {
                        quotedaily.TransationdataStringTX,
                        Convert.ToString(quotedaily.OpenpriceTX),
                        Convert.ToString(quotedaily.HighpriceTX),
                        Convert.ToString(quotedaily.LowpriceTX),
                        Convert.ToString(quotedaily.ClosepriceTX),
                        Convert.ToString(quotedaily.VolumeSizeTX),
                        Convert.ToString(quotedaily.AdjClosePriceTX)                    
                        }
                    );
            }

            return datatable;
        }
    }
}
